#include "Blocks/BottomSuckerBlock.h"
#include "Engine/Point3.hpp"
#include "Managers/BlocksManager.h"
#include "GameSingleton.h"
#include "Subsystems/SubsystemTerrain.h"

namespace PocketSurvival
{
	BottomSuckerBlock::BottomSuckerBlock() 
	{
		addInheritance(this);
	}

    BlockPlacementData BottomSuckerBlock::getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult)
    {
		Point3 point = raycastResult.cellFace.point + CellFace::FaceToPoint3(raycastResult.cellFace.face);
		int32_t cellValue = subsystemTerrain->getCellValue(point.posX, point.posY, point.posZ);
		int32_t num  = Terrain::ExtractContents(cellValue);
		int32_t data = Terrain::ExtractData(cellValue);
		Block *obj = GameSingleton::blocksManager->blocks[num];
		int32_t face = 0;
		BlockPlacementData result;
		if (obj->isBlock<WaterBlock*>() == true)
		{
			result.cellFace = raycastResult.cellFace;
			result.value = Terrain::MakeBlockValue(getIndex(), 0, SetSubvariant(SetFace(data, raycastResult.cellFace.face), face));
			return result;
		}
		return result;
    }

    void BottomSuckerBlock::initialize()
    {
        subsystemTerrain = GameSingleton::singletonPtr->getSingleton<SubsystemTerrain>();
    }

} // namespace PocketSurvival
